﻿using Microsoft.CSharp.Activities;
using System;
using System.Activities;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WFExtended.Twitter.Activities.Designers;

namespace WFExtended.Twitter.Activities
{
    /// <summary>
    /// Returns a single Tweet, specified by the id parameter.
    /// </summary>
    [ToolboxBitmapAttribute(typeof(EntryPoint), "Resources.TweetsToolbox.bmp")]
    [Designer(typeof(TweetsIDDesigner))]
    [Description("Returns a single Tweet, specified by the id parameter.")]
    public class GetTweet : TwitterOperationInvoker<Status>
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="GetTweet"/> class.
        /// </summary>
        public GetTweet()
            : base("GetTweet")
        {
            TrimUser = new InArgument<bool>(new CSharpValue<bool>("false"));
            IncludeMyRetweet = new InArgument<bool>(new CSharpValue<bool>("true"));
            IncludeEntities = new InArgument<bool>(new CSharpValue<bool>("true"));
        }

        /// <summary>
        /// The  ID of the desired status.
        /// <remarks>
        /// Required Argument
        /// </remarks>
        /// </summary>
        /// <value>
        /// The  ID of the desired status.
        /// </value>
        [Browsable(true)]
        [Category("Parameters")]
        [Description("The  ID of the desired status.")]
        [RequiredArgument]
        public InArgument<string> ID { get; set; }

        /// <summary>
        ///  When set to either true, each tweet returned in a timeline will include a user object including only the status authors numerical ID.
        ///  <remarks>Required Argument</remarks>
        /// </summary>
        /// <value>
        ///   <c>true</c> if [trim user]; otherwise, <c>false</c>.
        /// </value>
        [Browsable(true)]
        [Category("Parameters")]
        [Description("Trim User")]
        [RequiredArgument]
        public InArgument<bool> TrimUser { get; set; }

        /// <summary>
        ///  When set to either true, any Tweets returned that have been retweeted by the authenticating user will include 
        /// an additional current_user_retweet
        /// </summary>
        /// <value>
        /// The include my retweet.
        /// </value>
        [Browsable(true)]
        [Category("Parameters")]
        [Description("Include My Retweet")]
        [RequiredArgument]
        public InArgument<bool> IncludeMyRetweet { get; set; }

        /// <summary>
        /// The entities node will be disincluded when set to false.
        /// </summary>
        /// <value>
        /// The entities node will be disincluded when set to false.
        /// </value>
        [Browsable(true)]
        [Category("Parameters")]
        [Description("The entities node will be disincluded when set to false.")]
        [RequiredArgument]
        public InArgument<bool> IncludeEntities { get; set; }

        /// <summary>
        /// Caches the metadata.
        /// </summary>
        /// <param name="metadata">The metadata.</param>
        protected override void CacheMetadata(System.Activities.NativeActivityMetadata metadata)
        {
            RuntimeArgument idArgument = new RuntimeArgument("ID", typeof(string), ArgumentDirection.In, true);
            metadata.Bind(ID, idArgument);
            metadata.AddArgument(idArgument);

            RuntimeArgument trimUserArgument = new RuntimeArgument("TrimUser", typeof(bool), ArgumentDirection.In, true);
            metadata.Bind(TrimUser, trimUserArgument);
            metadata.AddArgument(trimUserArgument);

            RuntimeArgument includeMyRetweetArgument = new RuntimeArgument("IncludeMyRetweet", typeof(bool), ArgumentDirection.In, true);
            metadata.Bind(IncludeMyRetweet, includeMyRetweetArgument);
            metadata.AddArgument(includeMyRetweetArgument);

            RuntimeArgument includeEntitiesArgument = new RuntimeArgument("IncludeEntities", typeof(bool), ArgumentDirection.In, true);
            metadata.Bind(IncludeEntities, includeEntitiesArgument);
            metadata.AddArgument(includeEntitiesArgument);

            base.CacheMetadata(metadata);
        }

        /// <summary>
        /// Executes the specified context.
        /// </summary>
        /// <param name="context">The context.</param>
        protected override void Execute(System.Activities.NativeActivityContext context)
        {
            Parameters.Clear();

            Parameters.Add("statusID", ID);
            Parameters.Add("trimUser", TrimUser);
            Parameters.Add("includeMyRetweet", IncludeMyRetweet);
            Parameters.Add("includeEntities", IncludeEntities);

            base.Execute(context);
        }
    }
}
